package com.miplus.ccrm.core.service.crd;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.common.JSysUser;
import com.miplus.ccrm.common.JUsrPerm;
import com.miplus.ccrm.core.controller.vo.credit.*;
import com.miplus.ccrm.core.pojo.CreditAccountOutbill;
import com.miplus.ccrm.core.mapper.CreditAccountOutbillMapper;
import com.miplus.ccrm.core.pojo.CreditCard;
import org.springframework.stereotype.Service;

/**
* @author pc
* @description 针对表【credit_account_outbill(信用卡账单已出账流水表)】的数据库操作Service实现
* @createDate 2024-04-29 11:22:45
*/
@Service
public class CreditAccountOutbillServiceImpl extends MPJBaseServiceImpl<CreditAccountOutbillMapper, CreditAccountOutbill>
    implements CreditAccountOutbillService{

    @Override
    public IPage<CrdBillTailResVo> crdOutBillList(JSysUser user, CrdBillTailReqVo paras)
    {//240303的账单，是按交易时间统计240204-240303这个区间
        String $usrid=user.getUsrid();
        String cardstar= JUsrPerm.getPermission(user,JUsrPerm.DISSTAR_CARD);
        String billday1= JPubUtils.BilldayToStartday(paras.getBillDay().substring(0,10));
        String billday2= paras.getBillDay().replace("-","").substring(0,8);
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                CrdBillTailResVo.class,
                new MPJLambdaWrapper<CreditAccountOutbill>()
                        .selectAs(String.format("fi_starSecu('%s','%s',t.card_nbr,'%s')",$usrid,JUsrPerm.DISSTAR_CARD,cardstar), CrdBillTailResVo::getCardNo)
                        .leftJoin(CreditCard.class,"cd",CreditCard::getCardNo,CreditAccountOutbill::getCardNbr)
                        .selectAll(CreditAccountOutbill.class)
                        .eq(CreditCard::getAcct,paras.getAcctNo())
                        .ge(CreditAccountOutbill::getValDate,billday1)
                        .le(CreditAccountOutbill::getValDate,billday2)
                        .orderByDesc(CreditAccountOutbill::getInpDate,CreditAccountOutbill::getInpTime)
        );
    }
}




